<?php
/**
 * Created by PhpStorm.
 * User: boye009
 * Date: 2016/3/16
 * Time: 14:01
 */

namespace Api\Domain;


use Bbs\Api\ForumAttachmentApi;
use Bbs\Api\ForumForumApi;
use Bbs\Api\ForumPostApi;
use Bbs\Api\ForumThreadApi;

class ForumForumDomain extends BaseDomain{

    protected $business_code = 'forumForum';

    protected $allowType = array("json", "rss", "html");

    public function query(){

        $this->checkVersion(100);
        addLog("ForumForum/query", $_GET, $_POST, $this->client_id . "调用论坛版块查询接口!");

        if(IS_POST){

            $page_no = $this -> _post('page_no',1);
            $page_size = $this -> _post('page_size',6);
            $img_num = $this -> _post('img_num',3);
            $fup = $this -> _post('fup',0);

            $page = array('curpage'=>$page_no,'size'=>$page_size);

            $order = "displayorder desc";
            $map = [
                'fup' => $fup,
            ];
            if($fup==0){
                $map['fid'] =['in','1,2,4,6'];
            }

            $result = apiCall(ForumForumApi::QUERY_WITH_COUNT,array($map,$page,$order));

            if($result['status']){
                $list = $result['info'];
                foreach($list['list'] as &$val){
                    //判断子论坛个数
                    $map = ['fup' => $val['fid']];
                    $result = apiCall(ForumForumApi::COUNT,array($map));
                    $sub_forum = $result['info'];
                    $val['sub_forum'] = $sub_forum;
                }

                //顶级论坛查首页帖子
                if($fup == 0){
                    $result = apiCall(ForumThreadApi::QUERY_HEAD_THREADS,array(4,$img_num));
                    if($result['status']){
                        $list['thread_list'] = $result['info'];
                    }
                }

                $this -> apiReturnSuc($list);
            }else{
                $this -> apiReturnErr($result['info']);
            }

        }

    }

    /**
     * 查询用户信息
     */
    private function getUserInfo($uid){
        $result = apiCall('Api/BbsUserCenter/userInfo',array($uid),'Domain');
        if($result['status']){
            return $result['info'];
        }else{
            $this->apiReturnErr('查询用户信息失败');
        }
    }

}